<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>

</body>
<script>
    let stack = [];
    let index = 0;
    function useState(defaultState) {
        stack[index] = stack[index] !== undefined ? stack[index] : defaultState;
        let i = index;
        const setState = function (newState) {
            stack[i] = newState;
            render();
        }
        return [stack[index++], setState];
    }
    let onClick;
    function render() {
        index = 0;
        const [count, setCount] = useState(0);
        const [sum, setSum] = useState(0);
        const [a, setA] = useState(0);
        console.log(count, sum, a);
        onClick = () => { setCount(2); setSum(9), setA(null), setA('A') }
        console.log(count, sum, a);
    }
    render()
    onClick()

</script>

</html>